<template>
	<view style="height: 100vh;background-color: white;">
		<view class="frame">
			<view>手机号码</view>
			<u--input
			    placeholder="请输入手机号码"
			    border="surround"
				type="number"
			    v-model="value"
				clearable
				maxlength="11"
			  ></u--input>
		<u-button class="btn" @click="query" type="primary" text="查询用户信息"></u-button>
		</view>
		<view v-if="userInfo != ''">
			<view style="padding: 20rpx 20rpx;background-color: #fff;">
				<view style="display: flex;align-items: center; width: 100%;border-bottom: 2rpx #eaebec solid;">
					<view style="flex: 1;margin-left: 15px;font-size: 38rpx;">头像</view>
			<u--image width="150" height="150" @click='btnphoto'  :src="userInfo.avatar" shape="circle" style="margin-right: 15px;"></u--image>
			</view>
			  <u-cell-group
			      :border="false">
			    <u-cell  title="房号" 
						 :value="detail.building_name + detail.building_num + detail.name"
			             :titleStyle="{'font-size':'38rpx'}"
			             :rightIconStyle="{'font-size':'30rpx'}"
			    ></u-cell>
			    <u-cell  title="业主" :value="userInfo.real_name" 
			             :titleStyle="{'font-size':'38rpx'}"
			             :rightIconStyle="{'font-size':'30rpx'}"
			    ></u-cell>
				<u-cell  title="手机号" :value="userInfo.tel" 
				         :titleStyle="{'font-size':'38rpx'}"
				         :rightIconStyle="{'font-size':'30rpx'}"
				></u-cell>
				<u-cell  title="性别" :value="userInfo.sex == 1? '男':'女'" 
				         :titleStyle="{'font-size':'38rpx'}"
				         :rightIconStyle="{'font-size':'30rpx'}"
				></u-cell>
				<u-cell  title="工作单位" :value="userInfo.word_unit" 
				         :titleStyle="{'font-size':'38rpx'}"
				         :rightIconStyle="{'font-size':'30rpx'}"
				></u-cell>
			  </u-cell-group>
			</view>
			<view style="padding: 0 40rpx;margin-top: 40rpx;display: flex;">
			  <u-button type="error" style="width: 40%;" size="large" @click="no">不是本人</u-button>
			  <u-button type="success" style="width: 40%;" v-if="show" size="large" @click="yes">确认无误</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	import Api from '@/util/api.js'
	export default {
		data() {
			return {
				value: '',
				type: 'text',
				detail:{
					room:{}
				},
				userInfo:'',
				show:true
				// {
				// 	add_ip: "192.168.0.157",
				// 	avatar: "http://192.168.0.157:8012/upload/attachment/fd/93fa771ee605787a2a202497cb298b.jpg",
				// 	birthday: "1982-01-01 00:00:00",
				// 	create_time: "2022-11-07 16:10:42",
				// 	email: "",
				// 	expire_time: 0,
				// 	extend: null,
				// 	id: 251,
				// 	id_card: "123456789123456789",
				// 	invitation_code: 0,
				// 	is_vip: 0,
				// 	last_login_ip: "192.168.0.157",
				// 	last_login_time: "2022-12-07 17:28:57",
				// 	mark: "",
				// 	money: "0.00",
				// 	nickname: "夏愚YoZzu",
				// 	pay_count: 0,
				// 	phone: "",
				// 	platform: "2",
				// 	real_name: "老夏",
				// 	role_id: 0,
				// 	sex: 1,
				// 	spread_count: 0,
				// 	status: 1,
				// 	status_desc: "启用",
				// 	tel: "13433397750",
				// 	type: 1,
				// 	update_time: "2022-12-07 17:28:57",
				// 	user_id: 0,
				// 	username: "oauth_usGmEgbxSw",
				// 	word_unit: "宝维",
				// }
			}
		},
		onLoad(e){
			var that = this
			// that.checkUser()
			// that.getUserRoom()
		},
		methods:{
			// 查询用户信息
			query(){
				var that = this
				var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
				 if (!myreg.test(that.value)) {
						// console.log()
						uni.$u.toast('请输入正确的手机号码')
				        return false;
				    } else {
						uni.showLoading({
							title: '加载中'
						});
						var data = {
							tel:that.value,
							type:1
						}
						Api.getDetail(data).then(res=>{
							console.log('获取用户信息成功',res.data)
							uni.hideLoading();
							if(!res.data.id){
								uni.$u.toast('找不到该手机号的用户')
							}else{
								// uni.$u.toast('我找到了')
								localStorage.setItem('userInfo',JSON.stringify(res.data))
								that.checkUser()
								that.getUserRoom()
							}
						})
				        // return true;
				    }
				
			},
			// 检查用户信息
			checkUser(){
				var that  = this
				var userInfo = that.userInfo;
					if(localStorage.getItem('userInfo')){
						that.userInfo = JSON.parse(localStorage.getItem('userInfo'))
					}else{
						uni.showToast({
						    icon: 'none',   
						    duration: 3000,
						    title: "当前用户未登录"
						});
						return;
					}
			},
			//获取用户居住的房间
			getUserRoom(){
				var that = this
				var data = {
					user_id:that.userInfo.id 
				}
				Api.getUserRoom(data).then(res=>{
					console.log('获取成功',res)
					that.detail = res.data
				})
			},
			
			// 不是本人
			no(){
				var that = this
				uni.showModal({
					title: '提示',
					content: '请到物业处修改用户信息并进行缴费',
					success: function (res) {
						if (res.confirm) {
							console.log('用户点击确定');
							that.show = false
						} else if (res.cancel) {
							console.log('用户点击取消');
							that.show = false
						}
					}
				});
			},
			// 是本人无误了
			yes(){
				uni.navigateTo({
					url: "../pay/pay?type=alipay"
				})
			}
		}
		
	}
</script>

<style lang="scss">
	*{	
		
	}
	.frame{
		display: flex;
		align-items: center;
		padding:0rpx 20rpx;
	}
	.btn{
		width: 25%;
		// margin-right: 20rpx;
	}
</style>
